package top.wuyang.trywork.interceptor;


import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import top.wuyang.trywork.util.IpUtils;


// @Component 表示该类是一个组件，可以被spring容器管理
@Component
@Slf4j
@RequiredArgsConstructor
public class AppInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 获取客户端的ip地址信息
        String ip = IpUtils.getIpAddr(request);
        // 获取请求路径信息
        String url = request.getRequestURI();
        log.debug("{}访问了{}", ip, url);
        return true;
    }
}
